<!DOCTYPE html>
<html lang="en" xmlns:th="http://www.w3.org/1999/xhtml">
<head th:replace="_fragments :: head(~{:: title})">
    <title>博客详情</title>
</head>
<body>
<!--导航-->
<nav th:replace="_fragments :: nav(1)"></nav>

<!--中间内容-->
<div id="waypoint" class="m-container-small m-padding-tb-huge animated fadeIn">
    <!--头部区域-->
    <div class="ui container">
        <div class="ui top attached segment">
            <div class="ui horizontal link list">
                <div class="item">
                    <img src="https://picsum.photos/id/275/150/150" th:src="@{${blog.user.avatar}}" alt=""
                         class="ui avatar image">
                    <div class="content"><a th:href="@{/about}" class="header" th:text="${blog.user.nickname}">凉夏</a></div>
                </div>
                <div class="item">
                    <i class="calendar icon"></i> <span th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd')}">2021-02-08</span>
                </div>
                <div class="item">
                    <i class="eye icon"> </i> <span th:text="${blog.views}">123</span>
                </div>
            </div>
        </div>

        <!--图片区域-->
        <div class="ui attached segment">
            <img src="https://picsum.photos/id/20/800/450" th:src="@{${blog.firstPicture}}" alt=""
                 class="ui fluid rounded image">
        </div>

        <!--内容区域-->
        <div class="ui attached padded segment">
            <div class="ui right aligned basic segment">
                <div class="ui orange label" th:text="${blog.flag}">原创</div>
            </div>

            <h2 class="center aligned ui header" th:text="${blog.title}">
                标题
            </h2>

            <!--中间主要内容-->
            <div id="content" class="typo typo-selection js-toc-content m-padding-lr-responsive m-padding-tb-large"
                 th:utext="${blog.content}"></div>

            <!--标签-->
            <div class="m-padding-lr-responsive">
                <div class="ui basic teal left pointing label" th:each="tag : ${blog.tags}" th:text="${tag.name}">方法论
                </div>
            </div>

            <!--赞赏-->
            <div th:if="${blog.appreciation}">
                <div class="ui center aligned basic segment">
                    <button id="payButton" class="ui orange basic circular button">赞赏</button>
                </div>

                <!--二维码-->
                <div class="ui payQR flowing popup transition hidden">
                    <div class="ui orange basic label">
                        <div class="ui images" style="font-size: inherit !important;">
                            <div class="image">
                                <img th:src="@{/images/pay.jpg}" alt="" class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>支付宝</div>
                            </div>

                            <div class="image">
                                <img th:src="@{/images/wechat.jpg}" alt="" class="ui rounded bordered image"
                                     style="width: 120px">
                                <div>微信</div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>

        </div>


        <!--信息区域-->
        <div class="ui attached info message" th:if="${blog.shareStatement}">
            <div class="ui middle aligned grid">
                <!--文字-->
                <div class="eleven wide column">
                    <div class="ui list">
                        <li>作者：<span th:text="${blog.user.nickname}">凉夏</span> <a th:href="@{/about}" target="_blank">
                            (联系作者) </a></li>
                        <li>发表时间：<span
                                th:text="${#dates.format(blog.updateTime, 'yyyy-MM-dd HH:mm')}">2021-02-08 09:06</span>
                        </li>
                        <li>版权声明：自由转载，非商用，转载时请注明转载地址</li>
                    </div>
                </div>

                <!--二维码-->
                <div class="five wide column">
                    <img th:src="@{/images/wechat.jpg}" alt="" class="ui right float rounded bordered image"
                         style="width: 110px">
                </div>
            </div>
        </div>

        <!--留言区域-->
        <div class="ui bottom attached segment" th:if="${blog.commentabled}">
            <div id="comment-container" class="ui teal segment">
                <div th:fragment="commentList">
                    <div class="ui comments" style="max-width: 100%;">
                        <h3 class="ui dividing header">评论</h3>
                        <div class="comment" th:each="comment : ${comments}">
                            <a class="avatar">
                                <img src="https://picsum.photos/id/275/150/150" th:src="@{${comment.avatar}}">
                            </a>
                            <div class="content">
                                <a class="author">
                                    <span th:text="${comment.nickname}">Matt</span>
                                    <div class="ui mini basic teal left pointing label m-padding-mini"
                                         th:if="${comment.adminComment}">博主
                                    </div>
                                </a>
                                <div class="metadata">
                                    <span class="date"
                                          th:text="${#dates.format(comment.createTime, 'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                </div>
                                <div class="text" th:text="${comment.content}">太赞了！</div>
                                <div class="actions">
                                    <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                       th:attr="data-commentid=${comment.id}, data-commentnickname=${comment.nickname}"
                                       onclick="reply(this)">回复</a>
                                </div>
                            </div>
                            <div class="comments" th:if="${#arrays.length(comment.replyComments)} > 0">
                                <div class="comment" th:each="reply : ${comment.replyComments}">
                                    <a class="avatar">
                                        <img src="https://picsum.photos/id/275/150/150" th:src="@{${reply.avatar}}">
                                    </a>
                                    <div class="content">
                                        <a class="author">
                                            <span th:text="${reply.nickname}">Matt</span>
                                            <div class="ui mini basic teal left pointing label m-padding-mini"
                                                 th:if="${reply.adminComment}">博主
                                            </div>
                                            <span th:text="|@ ${reply.parentComment.nickname}|"
                                                  class="m-teal">@ abin</span>
                                        </a>
                                        <div class="metadata">
                                            <span class="date"
                                                  th:text="${#dates.format(reply.createTime, 'yyyy-MM-dd HH:mm')}">今天下午 5:42</span>
                                        </div>
                                        <div class="text" th:text="${reply.content}">太赞了！</div>
                                        <div class="actions">
                                            <a class="reply" data-commentid="1" data-commentnickname="Matt"
                                               th:attr="data-commentid=${reply.id}, data-commentnickname=${reply.nickname}"
                                               onclick="reply(this)">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>

                        <!--/*-->
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://picsum.photos/id/275/150/150">
                            </a>
                            <div class="content">
                                <a class="author">Elliot Fu</a>
                                <div class="metadata">
                                    <span class="date">昨天上午12:30</span>
                                </div>
                                <div class="text">
                                    <p>這對我的研究是非常有用.謝謝!</p>
                                </div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                            <div class="comments">
                                <div class="comment">
                                    <a class="avatar">
                                        <img src="https://picsum.photos/id/275/150/150">
                                    </a>
                                    <div class="content">
                                        <a class="author">Jenny Hess</a>
                                        <div class="metadata">
                                            <span class="date">刚刚</span>
                                        </div>
                                        <div class="text">艾略特你永远是多么正确 :)</div>
                                        <div class="actions">
                                            <a class="reply">回复</a>
                                        </div>
                                    </div>
                                </div>
                            </div>
                        </div>
                        <div class="comment">
                            <a class="avatar">
                                <img src="https://picsum.photos/id/275/150/150">
                            </a>
                            <div class="content">
                                <a class="author">Joe Henderson</a>
                                <div class="metadata">
                                    <span class="date">5 天以前</span>
                                </div>
                                <div class="text">老兄，这太棒了。非常感谢。</div>
                                <div class="actions">
                                    <a class="reply">回复</a>
                                </div>
                            </div>
                        </div>
                        <!--*/-->
                    </div>
                </div>
            </div>

            <!--评论区域-->
            <div id="comment-form" class="ui form">
                <input type="hidden" name="blog.id" th:value="${blog.id}">
                <input type="hidden" name="parentComment.id" value="-1">
                <div class="field">
                    <textarea name="content" placeholder="请输入评论信息..."></textarea>
                </div>
                <div class="fields">
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="user icon"></i>
                            <input type="text" name="nickname" placeholder="姓名"
                                   th:value="${session.user} != null ? ${session.user.nickname}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <div class="ui left icon input">
                            <i class="mail icon"></i>
                            <input type="text" name="email" placeholder="邮箱"
                                   th:value="${session.user} != null ? ${session.user.email}">
                        </div>
                    </div>
                    <div class="field m-mobile-wide m-margin-bottom-small">
                        <button id="commentpost-btn" type="button" class="ui teal button m-mobile-wide"><i
                                class="edit icon"></i>发布
                        </button>
                    </div>
                </div>
            </div>
        </div>
    </div>
</div>

<!--工具条-->
<div id="toolbar" class="m-padding m-fixed m-right-bottom" style="display: none">
    <div class="ui vertical icon buttons ">
        <button type="button" class="ui toc teal button">目录</button>
        <a href="#comment-container" class="ui teal button">留言</a>
        <button class="ui wechat icon button"><i class="weixin icon"></i></button>
        <div id="toTop-button" class="ui icon button"><i class="chevron up icon"></i></div>

    </div>
</div>

<div class="ui toc-container flowing popup transition hidden" style="width: 250px; !important;">
    <ol class="js-toc"></ol>
</div>

<div id="qrcode" class="ui wechat-qr flowing popup transition hidden" style="width: 130px !important;">
    <!--<img src="./static/images/wechat.jpg" alt="" class="ui rounded image" style="width: 120px !important;">-->
</div>

<br>
<br>
<br>
<!--底部footer-->
<footer th:replace="_fragments :: footer"></footer>

<!--/*/<th:block th:replace="_fragments :: script">/*/-->
<!--/*/</th:block>/*/-->

<script th:inline="javascript">
    $('.menu.toggle').click(function () {
        $('.m-item').toggleClass('m-mobile-hide')
    });

    $('#payButton').popup({
        popup: $('.payQR.popup'),
        on: 'click',
        position: 'bottom center'
    });

    $('.wechat').popup({
        popup: $('.wechat-qr'),
        on: 'hover',
        position: 'left center'
    });

    var server = /*[[#{blog.server}]]*/"";
    var url = /*[[@{/blog/{id}(id=${blog.id})}]]*/"";
    var qrcode = new QRCode("qrcode", {
        text: server + url,
        width: 110,
        height: 110,
        colorDark: "#000000",
        colorLight: "#ffffff",
        correctLevel: QRCode.CorrectLevel.H
    });

    var waypoint = new Waypoint({
        element: document.getElementById('waypoint'),
        handler: function (direction) {
            if (direction == 'down') {
                $('#toolbar').show(500);
            } else {
                $('#toolbar').hide(500);
            }
            console.log('Scrolled to waypoint!')
        }
    })

    tocbot.init({
        // Where to render the table of contents.
        tocSelector: '.js-toc',
        // Where to grab the headings to build the table of contents.
        contentSelector: '.js-toc-content',
        // Which headings to grab inside of the contentSelector element.
        headingSelector: 'h1, h2, h3',
        // For headings inside relative or absolute positioned containers within content.
        hasInnerContainers: true,
    });

    $('.toc.button').popup({
        popup: $('.toc-container.popup'),
        on: 'click',
        position: 'left center'
    });

    $('#toTop-button').click(function () {
        $(window).scrollTo(0, 500)
    });

    //表单验证
    $('.ui.form').form({
        fields: {
            title: {
                identifier: 'content',
                rules: [{
                    type: 'empty',
                    prompt: '请输入评论内容'
                }]
            },
            content: {
                identifier: 'nickname',
                rules: [{
                    type: 'empty',
                    prompt: '请输入你的昵称'
                }]
            },
            type: {
                identifier: 'email',
                rules: [{
                    type: 'email',
                    prompt: '请填写正确的邮箱地址'
                }]
            }
        }
    });

    $(function () {
        $("#comment-container").load(/*[[@{/comments/{id}(id=${blog.id})}]]*/"");
    });

    $('#commentpost-btn').click(function () {
        var boo = $('.ui.form').form('validate form');
        if (boo) {
            console.log("校验成功");
            postData();
        } else {
            console.log("校验失败");
        }
    });

    function postData() {
        $("#comment-container").load(/*[[@{/comments}]]*/"", {
            "parentComment.id": $("[name='parentComment.id']").val(),
            "blog.id": $("[name='blog.id']").val(),
            "nickname": $("[name='nickname']").val(),
            "email": $("[name='email']").val(),
            "content": $("[name='content']").val()
        }, function (responseTxt, statusTxt, xhr) {
            clearContent();
        });
    }

    function clearContent() {
        $("[name='content']").val('');
        $("[name='parentComment.id']").val(-1);
        $("[name='content']").attr("placeholder", "请输入评论信息...");
    }

    function reply(obj) {
        var commentId = $(obj).data('commentid');
        var commentNickname = $(obj).data('commentnickname');
        $("[name='content']").attr("placeholder", "@" + commentNickname).focus();
        $("[name='parentComment.id']").val(commentId);
        $(window).scrollTo($('#comment-form'), 500);
    }
</script>
</body>
</html>